import { Handlers } from "$fresh/server.ts";
import { deleteCookie } from "$std/http/cookie.ts";

export const handler: Handlers = {
  GET(req) {
    const url = new URL(req.url);
    const headers = new Headers();

    // 删除当前使用的v3版本cookie
    deleteCookie(headers, "admin_session_token_v3", { path: "/", domain: url.hostname });
    
    // 删除旧版本cookies以确保完全退出
    deleteCookie(headers, "admin_session_token_v2", { path: "/", domain: url.hostname });
    deleteCookie(headers, "admin_session_token", { path: "/", domain: url.hostname });
    
    // 可以添加一个查询参数来显示退出成功消息
    headers.set("Location", "/?logout_success=true");

    return new Response(null, {
      status: 303, // See Other for GET request logout
      headers,
    });
  },
}; 